package com.bwf.lgqingdan.mvp.presenter.impl;

import android.content.Context;

import com.bwf.lgqingdan.entity.ResponseHotKeywords;
import com.bwf.lgqingdan.mvp.model.SearchModel;
import com.bwf.lgqingdan.mvp.model.impl.SearchModelImpl;
import com.bwf.lgqingdan.mvp.presenter.SearchPresenter;
import com.bwf.lgqingdan.mvp.view.SearchView;

import java.util.List;

/**
 * Created by Administrator on 2016/11/19.
 */

public class SearchPresenterImpl implements SearchPresenter, SearchModel.Callback {
    private SearchModel model;
    private SearchView view;

    public SearchPresenterImpl(Context context,SearchView view) {
        this.view = view;
        this.model = new SearchModelImpl(context);
    }

    @Override
    public void loadHotKeywords() {
        model.loadHotSearchKeys(this);
    }

    @Override
    public void loadHistoryKeywords() {
        model.loadHistorySearchKeywords(this);
    }

    @Override
    public void addKeyword(String keyword) {
        model.addHistoryKeyword(keyword,this);
    }

    @Override
    public void ClearHistoryKeywords() {
        model.clearHistoryKeywords();
    }


    @Override
    public void loadHotSearchKeys(List<ResponseHotKeywords.DataBean.KeywordsBean> keywords) {
        view.showHotSearchKeywords(keywords);
    }

    @Override
    public void loadFailed(String failedMsg) {
        view.showLoadHotKeywordsFailed(failedMsg);
    }

    @Override
    public void loadHistorySearchKeywordsSuccess(List<String> historyKeywords) {
        if(historyKeywords != null && historyKeywords.size() != 0){
            view.showHistoryKeywords(historyKeywords);
        }else{
            view.showNoHistory();
        }
    }
    @Override
    public void refreshHistoryKeywords(List<String> keywords) {
        view.refreshHistoryKeywords(keywords);
    }
}
